# reference https://github.com/trion-development/docker-ng-cli

FROM 172.16.1.99/frontend/flash-ui/build/ci-base-10.16

ARG APP_DIR="/usr/src/app"

# ENV NPM_CONFIG_LOGLEVEL warn

COPY ./package.json .npmrc $APP_DIR/

# npm 5 uses different userid when installing packages, as workaround su to node when installing
# see https://github.com/npm/npm/issues/16766
RUN set -xe \
    && apt-get update \
    && apt-get install -y \
        sshpass \
        unzip \
    && wget -N https://npm.taobao.org/mirrors/chromedriver/87.0.4280.88/chromedriver_linux64.zip -P ~/Downloads \
    && unzip ~/Downloads/chromedriver_linux64.zip -d ~/Downloads \
    && mv -f ~/Downloads/chromedriver /usr/local/share/ \
    && chmod +x /usr/local/share/chromedriver \
    && ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver \
    && ln -s /usr/local/share/chromedriver /usr/bin/chromedriver \
    && (cd $APP_DIR; npm i --verbose) \
    && (npm cache clean --force)

WORKDIR $APP_DIR
